function vol_out = rescale_ct(vol_in)
%rescale_ct change ct's value to have adequate contrast
% we put 
% air at 100
% brain at 150


h = hist(reshape(vol_in,numel(vol_in),1),0:255);
[peaks,loc] = findpeaks(h, 'SORTSTR', 'descend', 'NPEAKS', 3);
loc = sort(loc);
%y = ax + b
a = 50 / (loc(3) - loc(2));
b = 100 - a * loc(2);
vol_out = a * vol_in + b;
vol_out(vol_out < 0) = 0;
vol_out(vol_out > 255) = 255;
end

